package com.easy.clickhouse;

/**
 * 服务器定义
 * @author junlei.xie
 *
 */
public class ClickHouseServer {
    
    public static final String URL_PREFIX = "jdbc:clickhouse://";
    
    /** 所属分片*/
    private int shard;
    
    /** 所属复制*/
    private int replica;
    
    /** 地址*/
    private String host;
    
    /** http端口*/
    private int http;
    
    /** tcp端口*/
    private int tcp;
    
    /** 存活状态*/
    private boolean alive = true;

    public int getShard() {
        return shard;
    }

    public void setShard(int shard) {
        this.shard = shard;
    }

    public int getReplica() {
        return replica;
    }

    public void setReplica(int replica) {
        this.replica = replica;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getHttp() {
        return http;
    }

    public void setHttp(int http) {
        this.http = http;
    }

    public int getTcp() {
        return tcp;
    }

    public void setTcp(int tcp) {
        this.tcp = tcp;
    }

    public boolean isAlive() {
        return alive;
    }

    public void setAlive(boolean alive) {
        this.alive = alive;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    private transient String url;
    
    public String getUrl() {
        if (url != null) {
            return url;
        }
        synchronized (this) {
            if (url == null) {
                url = URL_PREFIX + host + ":" + http;
            }
        }
        return url;
    }
    
    public void updateAlive(boolean alive) {
        this.alive = alive;
    }
}
